
pkgname=bash
_basever=4.4
_patchlevel=023
pkgver=${_basever}.${_patchlevel}
pkgrel=1
pkgdesc="The GNU Bourne Again shell"
arch=('x86_64')
license=('GPL')
url="https://www.gnu.org/software/bash/bash.html"
groups=('base')
backup=(etc/bash.bash{rc,_logout} etc/skel/.bash{rc,_profile,_logout})
depends=('readline>=7.0' 'glibc')
provides=('sh')
source=("https://ftp.gnu.org/gnu/bash/bash-${_basever}.tar.gz"
        'dot.bashrc'
        'dot.bash_profile'
        'dot.bash_logout'
        'system.bashrc'
        'system.bash_logout')
if [ ${_patchlevel} -gt 000 ]; then
    for (( p=1; p<=$((10#${_patchlevel})); p++ )); do
        source=(${source[@]} https://ftp.gnu.org/gnu/bash/bash-${_basever}-patches/bash${_basever//./}-$(printf "%03d" $p))
    done
fi
md5sums=('148888a7c95ac23705559b6f477dfe25'
         '027d6bd8f5f6a06b75bb7698cb478089'
         '2902e0fee7a9168f3a4fd2ccd60ff047'
         '42f4400ed2314bd7519c020d0187edc5'
         '3546099a1b2f667adc9794f52e78e35b'
         '472f536d7c9e8250dc4568ec4cfaf294'
         '817d01a6c0af6f79308a8b7b649e53d8'
         '765e14cff12c7284009772e8e24f2fe0'
         '49e7da93bf07f510a2eb6bb43ac3e5a2'
         '4557d674ab5831a5fa98052ab19edaf4'
         'cce96dd77cdd1d293beec10848f6cbb5'
         'd3379f8d8abce5c6ee338f931ad008d5'
         'ec38c76ca439ca7f9c178e9baede84fc'
         'e0ba18c1e3b94f905da9b5bf9d38b58b'
         'e952d4f44e612048930c559d90eb99bb'
         '57b5b35955d68f9a09dbef6b86d2c782'
         'cc896e1fa696b93ded568e557e2392d5'
         'fa47fbfa56fb7e9e5367f19a9df5fc9e'
         '5e6a20166efe166267972cc78025417b'
         '00a8877a8787dbd78d97767db1115b0a'
         '2409586fd19e3104197ead86ce549eca'
         '4b31183db086daf8be8943d7f7ea7526'
         'c15c8844f1eb87bdbcde71417c9bd342'
         'b25e3373fc8de00523116dfe151ac4e0'
         '8f43e1d277b02f3319a34c1cd4a4ff3e'
         '5217ff08c444446ec306dce60437c288'
         '282c7d9b38da8005d25b4f816328a2f4'
         '0b709c9d7f8e6cf267a8b863efb899f7'
         'fe2e0ca4cf9409ff0e9428e1236f983e')

build() {
  cd ${pkgname}-${_basever}
  for (( p=1; p<=$((10#${_patchlevel})); p++ )); do
    msg "applying patch bash${_basever//./}-$(printf "%03d" $p)"
    patch -p0 -i $srcdir/bash${_basever//./}-$(printf "%03d" $p)
  done

  _bashconfig=(-DDEFAULT_PATH_VALUE=\'\"/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin\"\'
               -DSTANDARD_UTILS_PATH=\'\"/usr/bin:/bin:/usr/sbin:/sbin\"\'
               -DSYS_BASHRC=\'\"/etc/bash.bashrc\"\'
               -DSYS_BASH_LOGOUT=\'\"/etc/bash.bash_logout\"\')
  export CFLAGS="${CFLAGS} ${_bashconfig[@]}"

  ./configure --prefix=/usr \
    --with-curses \
    --enable-readline \
    --without-bash-malloc \
    --with-installed-readline \
    --bindir=/bin \
    --mandir=/usr/share/man \
    --infodir=/usr/share/info
  make
}

check() {
  cd ${pkgname}-${_basever}
  
  make check
}

package() {
  cd ${pkgname}-${_basever}
  make DESTDIR=${pkgdir} install

  # bash is default /bin/sh
  cd ${pkgdir}/bin
  ln -s bash sh

  install -dm755 ${pkgdir}/etc/skel/
  
  # system configuration files
  install -m644 ${srcdir}/system.bashrc ${pkgdir}/etc/bash.bashrc
  install -m644 ${srcdir}/system.bash_logout ${pkgdir}/etc/bash.bash_logout
  
  # user configuration files
  install -m644 ${srcdir}/dot.bashrc ${pkgdir}/etc/skel/.bashrc
  install -m644 ${srcdir}/dot.bash_profile ${pkgdir}/etc/skel/.bash_profile
  install -m644 ${srcdir}/dot.bash_logout ${pkgdir}/etc/skel/.bash_logout
}
